
        String.prototype.endWith = function (str) {
            if (str == null || str == "" || this.length == 0 || str.length > this.length)
                return false;
            if (this.substring(this.length - str.length) == str)
                return true;
            else
                return false;
            return true;
        }

        String.prototype.startWith = function (str) {
            if (str == null || str == "" || this.length == 0 || str.length > this.length)
                return false;
            if (this.substr(0, str.length) == str)
                return true;
            else
                return false;
            return true;
        }
        
        function mouse(){
			 try{
			    var a = $.ui.mouse.prototype._mouseMove;
			    $.ui.mouse.prototype._mouseMove = function (b)
			    { b.button = 1; a.apply(this, [b]); }
			 }catch(e){}
        }
function redirect(url) {
    window.location.replace(url);

}
///通用弹出层
function doTips(title, content, width, height, draggable, timeout, url, isshadow, cssName, showCloseBtn) {
    tipsWindown(title, content, width, height, draggable, timeout, url, isshadow, cssName, showCloseBtn);
}

function hover(target) {
    target.style.backgroundColor = "#F5F9FD";

}
function out(target) {
    target.style.backgroundColor = "";
}

function closeTargetDialogForm(formSelector)
{
	var _form = $(formSelector);
	if(_form!=null && _form.dialog!=undefined)
		$(_form).dialog('close');
}


function loadChildSkin()
{
	if($("#skin_css").length>0)
	{ 
		var skin_name = getDataFromCookieOrDefaultskin("SkinFor_.child","themes/css/ui.c.blue.css");
		//alert(skin_name);
	    var child =   skin_name  ;
	     
	    var childSkinObject =  document.getElementById("skin_css");
	 
	 if (childSkinObject != undefined  )
	    {    
	    	childSkinObject.href = child;
	    
	    }
	    else {
	    	childSkinObject ='<link id="skin_css" rel="stylesheet" type="text/css"'+
				'href="'+child+'"></link>';
	        	 
				$(childSkinObject).appendTo("head");
	        } 
	}
}


$(document).ready(function () {  // 
	loadChildSkin();
	mouse();
	
    $(".WaterMark").each(function (i) {
        var t = $(".WaterMark")[i];
        if (t == null || t == undefined)
            return;
        var jT = $("#" + t.id);
        if (jT.val().length == 0) {
            jT.val(t.title);
        } else
            jT.removeClass("WaterMark");
    });

    //隔行变色(数据列表)
    $(".PageChild_List_main tr:odd").addClass("PageChild_List_tr");

    //设置水印
    $(".WaterMark").focus(function () {

        if ($(this).val() == $(this).attr("title"))
        { $(this).val('').removeClass("WaterMark"); }
    }).blur(function () {
        if ($.trim($(this).val()).length == 0) {
            $(this).val($(this).attr("title")).addClass("WaterMark");
        }
    });

    initialButton();
    initialDateTextBox();
    registeTurnToPage("#turnToPageButton","#goPageNum");
    $(".reset-input-button").click(function(){
    	var target = $(this).attr("targetContainer");
    	clearInputControlValue(target);
    	
    });
    
    $(".dialogFormCloseButton").click(function (){
    	var formSelector = $(this).attr("dialogForm");
    	if(formSelector!=null && formSelector!=undefined)
    	{
    		closeTargetDialogForm(formSelector);
    	}
    	
    });
});

function clearInputControlValue(target)
{
	if(target==undefined)
	{
		$(".clearable").val("");
		return;
	}

	$(target).find(".clearable").val("");
}

function checkAll() {
    $(".PageChild_List_main tr :checkbox").attr("checked", $("input[name='chkall']").attr("checked"));
}

function checkDeleteAll(msg) {
    var count = $(".PageChild_List_main tr :checkbox[checked=true]").length;

    if (count > 0) {
        return confirm("确实要删除选中的 " + count + " 条 " + msg + "吗?");
    }
    alert("没有选中记录,或者没有数据.");
    return false;
} 
 
//关闭弹出层
function tipsClose() {
    $("#windownbg").hide();
    $("#windown-box").hide();
} 
function initialDateTextBox() {
    //控制时间 
    $(".NeedDate").datepicker({ changeMonth: true,
        changeYear: true,
        showAnim: '',
        showButtonPanel: true,
        dateFormat:'yy-mm-dd',
        currentText: '今天' 
    });
}

function initialButton() {
    $(".ui-button").button();
}
function foreachHandler(items,callBack)
{	
    var result = "";
	for(var index in items)
	{ 
		result +=callBack(items[index]);
	}
	return result;
}


function toggleObject(current, tDiv, symbolChar, otherChar) {
    var object = $(tDiv).css("display");
    var isOpen = object != "none";

    if (isOpen) {
        $(tDiv).hide(); //.slideUp("slow");//.delay("300") ; //.delay("600").hide(); 
    }
    else {
        $(tDiv).show(); //.slideDown("slow");//
    }
    $(current).text($(current).text() == symbolChar ? otherChar : symbolChar);
}



$.fn.numeral = function() {
    $(this).css("ime-mode", "disabled");
    this.bind("keypress",function() {
        if (event.keyCode == 46) {
            if (this.value.indexOf(".") != -1) {
                return false;
            }
        } else {
            return event.keyCode >= 46 && event.keyCode <= 57;
        }
    });
    this.bind("blur", function() {
        if (this.value.lastIndexOf(".") == (this.value.length - 1)) {
            this.value = this.value.substr(0, this.value.length - 1);
        } else if (isNaN(this.value)) {
            this.value = "";
        }
    });
    this.bind("paste", function() {
        var s = clipboardData.getData('text');
        if (!/\D/.test(s));
        value = s.replace(/^0*/, '');
        return false;
    });
    this.bind("dragenter", function() {
        return false;
    });
    this.bind("keyup", function() {
    if (/(^0+)/.test(this.value)) {
        this.value = this.value.replace(/^0*/, '');
        } 
    });
};


//registe go to page "GO" Button Click Event
 function registeTurnToPage(btnId,numBoxId){ 
	 $(numBoxId).numeral();
	 
	 $(numBoxId).keydown(function(e){
		  if(e.keyCode=='13')
		  { 
			  $(btnId).click(); 
		  }
	 });
	 
	$(btnId).click(function(){
		
		var max = $(numBoxId).attr("max");
		
		var min = $(numBoxId).attr("min");
		var val = $(numBoxId).val();
	     
		if( goToPage==undefined|| max==undefined)
			return ;
		if(min ==undefined)
			min=1;
		 
		max = parseFloat(max);
		min = parseFloat(min);
		if($.trim(val).length==0 ||(val>max) || val<min ) 
		{
			 
			return;		
		}
		else 			
		{	 
			goToPage(val);		
		}
	});
		
} 
 
 

function isNumber(oNum) 
{ 
if(!oNum) return false; 
var strP=/^\d+(\.\d+)?$/; 
if(!strP.test(oNum)) return false; 
try{ 
if(parseFloat(oNum)!=oNum) return false; 
} 
catch(ex) 
{ 
return false; 
} 
return true; 
}



 function getParentSkinName()
 {
	 
	 
	 if(document.parent!=null && document.parent.getParentSkinName!=undefined)
		 return document.parent.getParentSkinName(); 
 }
 
 
 jQuery.cookie = function(name, value, options) {
	    if (typeof value != 'undefined') { // name and value given, set cookie
	        options = options || {};
	        if (value === null) {
	            value = '';
	            options.expires = -1;
	        }
	        var expires = '';
	        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
	            var date;
	            if (typeof options.expires == 'number') {
	                date = new Date();
	                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
	            } else {
	                date = options.expires;
	            }
	            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
	        }
	        var path = options.path ? '; path=' + options.path : '';
	        var domain = options.domain ? '; domain=' + options.domain : '';
	        var secure = options.secure ? '; secure' : '';
	        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	    } else { // only name given, get cookie
	        var cookieValue = null;
	        if (document.cookie && document.cookie != '') {
	            var cookies = document.cookie.split(';');
	            for (var i = 0; i < cookies.length; i++) {
	                var cookie = jQuery.trim(cookies[i]);
	                // Does this cookie string begin with the name we want?
	                if (cookie.substring(0, name.length + 1) == (name + '=')) {
	                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
	                    break;
	                }
	            }
	        }
	        return cookieValue;
	    }
	};

//
function getDataFromCookieOrDefaultskin(key, defValueIfNull) {
    var skin = $.cookie("'" + key + "'"); //读取Cookie值 
    if (skin == null)
        skin = defValueIfNull;

    return skin;
}